package queue

import (
	"errors"

	"hyper/supports/configs"
	"hyper/supports/queue/abstruct"
	"hyper/supports/queue/factories"
)

// 选择队列压入任务
func Dispatch(obj *abstruct.QueueObj) error {
	// 获取配置文件内得驱动
	queueType := configs.GetString("queue.default")
	switch queueType {
	case "redis":
		return new(factories.RedisQueue).New(obj).MakeJson().Producer()
	case "rabbitmq":
		return new(factories.RabbitMqQueue).New(obj).MakeJson().Producer()
	case "kafka":
		return new(factories.KafkaQueue).New(obj).MakeJson().Producers()
	}

	return errors.New("队列类型不存在")
}
